#ifdef __cplusplus
extern "C"
{
#endif

#include <stdio.h>
#include <sys/types.h>
#include <pthread.h>
#include "swap.h"
#include "apple.h"

void *swapapple(void *x)
{
    swapvec((number *)x);
}

void *addapple(void *x)
{
    int sum;
    sum = addvec((number *)x);
    printf("sum = %d\n", sum);
}


int main()
{
    int x = 12, y = 80;
    number apple;
    pthread_t threadA, threadB;
    pthread_rwlock_t aaa;

    apple.x = x;
    apple.y = y;

    printf("x = %d, y = %d\n", x, y);

    pthread_rwlock_init(&apple.rwlock, NULL);
    pthread_create(&threadA, NULL, swapapple, &apple);
    pthread_create(&threadB, NULL, addapple, &apple);
    pthread_join(threadA, NULL);
    pthread_join(threadB, NULL);

    printf("apple.x = %d, apple.y = %d\n", apple.x, apple.y);

    return 0;
}

#ifdef __cplusplus
}
#endif
